package com.cxyd.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxyd.common.page.PageData;
import com.cxyd.common.service.impl.CrudServiceImpl;
import com.cxyd.modules.wms.dao.StockSapDao;
import com.cxyd.modules.wms.dto.StockSapDTO;
import com.cxyd.modules.wms.entity.StockSapEntity;
import com.cxyd.modules.wms.service.StockSapService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class StockSapServiceImpl extends CrudServiceImpl<StockSapDao, StockSapEntity, StockSapDTO> implements StockSapService {
    @Override
    public PageData<StockSapDTO> page(Map<String, Object> params) {
        //查询sap库存数据
        IPage<StockSapEntity> page = baseDao.selectPage(
                getPage(params, "id", true),
                getWrapper(params)
        );
        return getPageData(page, StockSapDTO.class);
    }

    @Override
    public QueryWrapper<StockSapEntity> getWrapper(Map<String, Object> params) {
        String spuNo = (String) params.get("spuNo");
        QueryWrapper<StockSapEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(spuNo), "MATNR", spuNo);
        return wrapper;
    }

    @Override
    public void truncateTable() {
        baseDao.truncateTable();
    }
}
